#include<iostream>
#include<string>
#include<map>
using namespace std;
const int N = 1e5 + 10;
int s1[N];
int s2[N];
string str;
int n;
int main()
{
	cin >> n;
	cin >> str;
	str = " " + str;
	/*for (int i = 1; i <= n; i++) {
		s[i] = s[i - 1] + str[i] - '0';
	}*/
	for (int i = 1; i <= n; i++) {
		int k = str[i] - '0';
		if (k) {
			s1[i] = s1[i - 1] + 1;
		}
		else {
			s2[i] = s2[i - 1] + 1;
		}
	}
	if (s1[n] == n || s1[n] == 0 || s2[n] == n || s2[n] == 0) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	/*for (int i = 1; i <= n - 1; i++) {
		for (int j = i + 1; j <= n; j++) {
			if ( 2 * (s[j] - s[i - 1]) == j - i + 1) {
				ans = max(ans, j - i + 1);
			}
		}
	}*/
	cout << ans << endl;
	return 0;
}